package com.hankol.newretail.adapter.details

import android.view.View
import android.widget.ImageView
import com.baselibrary.extension.checkValue
import com.baselibrary.manager.SensorsDataManager
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils
import com.baselibrary.utils.GlideUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.goods_details.GoodsDetails
import com.hankol.newretail.bean.goods_details.GrassShowBean

/**
 * @author: 关忆北、
 * @date: 2022/7/29
 * @Des：种草秀
 */
class GoodsPlantAdapter : BaseQuickAdapter<GrassShowBean, BaseViewHolder>(R.layout.item_goods_plant_layout) {
    private var mOnItemClickListener: OnItemClickListener? = null
    private var mGoodsDetail: GoodsDetails? = null
    fun setGoodsDetail(mGoodsDetail: GoodsDetails) {
        this.mGoodsDetail = mGoodsDetail
    }

    fun setOnItemClickListener(mOnItemClickListener: OnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener
    }

    override fun convert(helper: BaseViewHolder, item: GrassShowBean) {
        GlideUtils.loadImg_101(mContext.applicationContext, item.cover, helper.getView(R.id.iv_plant_cover))
        val ivPlantVideo = helper.getView<ImageView>(R.id.iv_plant_video)
        ivPlantVideo.visibility = if (item.showType == 1) View.GONE else View.VISIBLE

        helper.itemView.setOnClickListener {
            mGoodsDetail?.let {
                SensorsDataManager.instance.productShow(it.spuId.toString(), if (it.shopInfo == null) "酣客总社" else it.shopInfo.name.checkValue(), it.name.checkValue(), item.id.toString(), item.tagName.checkValue(), item.tagCategoryName.checkValue())
            }
            mOnItemClickListener?.itemClickListener()
            if (item.showType == 1) {
                val hashMap = HashMap<String, Any>()
                hashMap["id"] = item.id
                ARouterUtils.jump(ActivityRouter.ACTIVITY.IMAGE_DETAIL, hashMap)
            } else {
                val hasMap: HashMap<String, Any> = hashMapOf()
                hasMap["id"] = item.id
                hasMap["isOpenComment"] = false
                ARouterUtils.jump(ActivityRouter.ACTIVITY.READ_VIDEO_DETAIL, hasMap)
            }

        }
    }

    interface OnItemClickListener {
        fun itemClickListener()
    }

}